package cn.com.inossem.utils.wangyi.session;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import cn.com.inossem.utils.wangyi.CustomAttachParser;
import cn.com.inossem.utils.wangyi.GuessAttachment;
import cn.com.inossem.utils.wangyi.StickerAttachment;
import cn.com.inossem.utils.wangyi.session.action.GuessAction;
import cn.com.inossem.utils.wangyi.session.viewholder.MsgViewHolderGuess;

import com.netease.nim.uikit.NimUIKit;
import com.netease.nim.uikit.session.SessionCustomization;
import com.netease.nim.uikit.session.actions.BaseAction;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;

/**
 * UIKit自定义消息界面用法展示类
 */
public class SessionHelper {

    private static SessionCustomization p2pCustomization;

    public static void init() {
        // 注册自定义消息附件解析器
        NIMClient.getService(MsgService.class).registerCustomAttachmentParser(new CustomAttachParser());

        // 注册各种扩展消息类型的显示ViewHolder
        registerViewHolders();
    }

    // 定制化单聊界面。如果使用默认界面，返回null即可
    public static SessionCustomization getP2pCustomization() {
        if (p2pCustomization == null) {
            p2pCustomization = new SessionCustomization() {
                // 由于需要Activity Result， 所以重载该函数。
                @Override
                public void onActivityResult(final Activity activity, int requestCode, int resultCode, Intent data) {
                    super.onActivityResult(activity, requestCode, resultCode, data);

                }

                @Override
                public MsgAttachment createStickerAttachment(String category, String item) {
                    return new StickerAttachment(category, item);
                }
            };

            // 背景
//            p2pCustomization.backgroundColor = Color.BLUE;
//            p2pCustomization.backgroundUri = "file:///android_asset/xx/bk.jpg";
//            p2pCustomization.backgroundUri = "file:///sdcard/Pictures/bk.png";
//            p2pCustomization.backgroundUri = "android.resource://com.netease.nim.demo/drawable/bk"

            // 定制加号点开后可以包含的操作， 默认已经有图片，视频等消息了
            ArrayList<BaseAction> actions = new ArrayList<>();
//            actions.add(new SnapChatAction());
            actions.add(new GuessAction());
            p2pCustomization.actions = actions;
            p2pCustomization.withSticker = true;
        }

        return p2pCustomization;
    }

    private static void registerViewHolders() {
        NimUIKit.registerMsgItemViewHolder(GuessAttachment.class, MsgViewHolderGuess.class);
    }
}
